/**
 * Created by liuzengrong on 2019/8/16.
 */
import React from 'react';
import { connect } from 'dva';
import { message } from 'antd';
import StandardModule from '@/components/hyperspace/modules/StandardModule';

/**
 * 自定义模块
 */
// @ts-ignore
const LocalModule: React.FC = ({ back, dispatch }) => (
  <StandardModule
    data={back.data}
    dictionary={[
      {
        name: 'orderNo',
        desc: '订单号',
        dataType: 'string',
      },
      {
        name: 'contractNo',
        desc: '合同协议号',
        dataType: 'string',
      },
      {
        name: 'declaratNo',
        desc: '报关单号',
        dataType: 'string',
      },
      {
        name: 'exportTime',
        desc: '出口日期',
        dataType: 'string',
      },
      {
        name: 'companyname',
        desc: '客户名称',
        dataType: 'string',
      },
      {
        name: 'drawbackAmount',
        desc: '退税金额',
        dataType: 'number',
      },
      {
        name: 'passStatus',
        desc: '放行状态',
        dataType: 'string',
      },
      {
        name: 'foxerStatus',
        desc: '外汇状态',
        dataType: 'string',
      },
      {
        name: 'invoiceStatus',
        desc: '发票状态',
        dataType: 'string',
      },
      {
        name: 'drawbackFianceStatus',
        desc: '退税融资状态',
        dataType: 'string',
      },
      {
        name: 'presentStatus',
        desc: '交单税局状态',
        dataType: 'string',
      },
      {
        name: 'transferAccountStatus',
        desc: '退税款到账状态',
        dataType: 'string',
      },
      {
        name: 'isperopeninvoice',
        desc: '预开票',
        dataType: 'string',
      },
    ]}
    config={{
      common: {
        formItemOptions: {
          username: {
            rules: [{ required: true, message: '该字段不能为空！' }],
          },
        },
      },
      search: {
        fields: ['username', 'mobile', 'email'], // 查询条件
        tabs: {
          field: 'status',
          tabItems: [
            {
              title: '全部',
              value: '',
              active: true,
            },
            {
              title: '待审核',
              value: 'TO_AUDIT',
            },
            {
              title: '审核通过',
              value: 'AUDIT_PASS',
            },
            {
              title: '审核失败',
              value: 'AUDIT_FAIL',
            },
            {
              title: '已上架',
              value: 'ONLINE',
            },
            {
              title: '已下架',
              value: 'OFFLINE',
            },
          ],
        }, // 状态栏
      },
      list: {
        url: '/api/back/query',
        fields: [
          'orderNo',
          'contractNo',
          'declaratNo',
          'exportTime',
          'companyname',
          'drawbackAmount',
          'foxerStatus',
          'invoiceStatus',
          'drawbackFianceStatus',
          'presentStatus',
          'passStatus',
          'transferAccountStatus',
          'isperopeninvoice',
        ], // 列表字段
        format: {
          username: {
            render: (value: any) => `格式化 - ${value}`,
          },
        },
        extensions: {
          operations: [
            (record: any) => (
              <a
                onClick={() => {
                  message.info(`扩展操作：${JSON.stringify(record)}`);
                }}
              >
                扩展操作
              </a>
            ),
          ],
        },
      },
      add: {
        url: '/api/back/create',
        // width: 680, // 非必填，默认680px
        // title: '新建表单', // 非必填，默认`新建`
        fields: [
          'orderNo',
          'contractNo',
          'declaratNo',
          'exportTime',
          'companyname',
          'drawbackAmount',
          'foxerStatus',
          'invoiceStatus',
          'drawbackFianceStatus',
          'presentStatus',
          'passStatus',
          'transferAccountStatus',
          'isperopeninvoice',
        ], // 新增表单字段
      },
      update: {
        url: '/api/back/update',
        // width: 680, // 非必填，默认680px
        // title: '新建表单', // 非必填，默认`新建`
        fields: [
          'orderNo',
          'contractNo',
          'declaratNo',
          'exportTime',
          'companyname',
          'drawbackAmount',
          'foxerStatus',
          'invoiceStatus',
          'drawbackFianceStatus',
          'presentStatus',
          'passStatus',
          'transferAccountStatus',
          'isperopeninvoice',
        ], // 修改表单字段
        primaryKeys: ['id'], // 主键字段列表
      },
      delete: {
        url: '/api/back/remove',
        batchDelete: false, // 是否开启批量删除
        fields: ['id'], // 删除依据字段
      },
    }}
    namespace="back"
    dispatch={dispatch}
  />
);

// @ts-ignore
export default connect(({ back }) => ({
  back,
}))(LocalModule);
